import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/guider_didi";

export const guider_info_api = (
  data: { guider_id: string },
  showError = true
) => {
  return Http.get<any>(`${baseUrl}/guider/info`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const guider_work_info_api = (
  data: { work_id: string },
  showError = true
) => {
  return Http.get<any>(`${baseUrl}/guider_work/info`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const user_follow_api = (
  data: { follow_id: string | number; type: number },
  showError = true
) => {
  return Http.post(`${baseUrl}/user/follow`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const guider_info_product_header_api = (
  data: { guider_id?: string; work_id?: string },
  showError = true
) => {
  return Http.get<{ items: any[] }>(
    `${baseUrl}/guider_info/product_header`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const guider_info_product_list_api = (
  data: {
    guider_id?: string;
    work_id?: string;
    cate_id: string;
  } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `${baseUrl}/guider_info/product_list`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const guider_info_share_note_list_api = (
  data: { guider_id?: string; work_id?: string } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `${baseUrl}/guider_info/share_note_list`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const guider_info_comment_header_api = (
  data: { guider_id?: string; work_id?: string; group_type?: number },
  showError = true
) => {
  return Http.get<any>(`${baseUrl}/guider_info/comment_header`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const guider_info_comment_list_api = (
  data: {
    guider_id?: string;
    work_id?: string;
    group_type?: number;
    type: number;
    sort: number;
  } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `${baseUrl}/guider_info/comment_list`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const guider_work_guider_list_api = (
  data: { work_id: string } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `${baseUrl}/guider_work/guider_list`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const note_types_api = (showError = true) => {
  return Http.get<any[]>(`${baseUrl}/note/types`).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const note_add_api = (data: any, showError = true) => {
  return Http.post(`${baseUrl}/note/add`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};
